#include "matrix_float.h"

using namespace frost;

matrix_float::matrix_float(void)
{
	create_matrix(0, 0);
}

matrix_float::matrix_float(int r, int c)
{
	create_matrix(r, c);
}

matrix_float::~matrix_float(void)
{
	delete_matrix();
}

void matrix_float::create_matrix(int r, int c)
{
	if( r == 0 && c == 0 )
		mptr = nullptr;
	else
	{
		mptr = new float*[r];
		for(int i = 0; i < r; i++)
			mptr[i] = new float[c];
	}
	r_size = r;
	c_size = c;
}

void matrix_float::delete_matrix()
{
	for(int i = 0; i < r_size; i++)
	{
		delete[] mptr[i];
		mptr[i] = nullptr;
	}
	delete[] mptr;
	mptr = nullptr;
	r_size = 0;
	c_size = 0;
}

void matrix_float::set(float value, int r, int c)
{
	if((r >= 0) && (r < r_size) && (c >= 0) && (c < c_size))
		mptr[r][c] = value;
}

void matrix_float::read_from_keyboard()
{
	cout << "Skriv in " << r_size << " rader, " << c_size << " kolumnar flyttal med ett mellanslag mellan varje: ";
	for(int i = 0; i < r_size; i++)
		for(int j = 0; j < c_size; j++)
			cin >> mptr[i][j];
}

void matrix_float::print()
{
	cout.precision(2);
	for(int i = 0; i < r_size; i++)
	{
		for(int j = 0; j < c_size; j++)
			cout << setw(5) << mptr[i][j];
		cout << endl;
	}
	cout << endl;
}
